package com.dengdai.applibrary.adapter;

import android.view.View;
import android.view.ViewGroup;

import com.dengdai.applibrary.annotation.InjectUtils;
import com.dengdai.applibrary.base.BaseCommAdapter;
import com.dengdai.applibrary.base.BaseViewHolder;

/**
 * @说明 Adapter基本数据类
 * @作者 LY
 * @时间 15/12/21 10:24
 * @版权 Copyright(c) 2015 LY-版权所有
 */
public class BasicDataAdapter<T> extends BaseCommAdapter {
    private BaseViewHolder<T> viewHolder;

    public BasicDataAdapter(BaseViewHolder<T> mViewHolder) {
        this.viewHolder = mViewHolder;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            viewHolder = viewHolder.createViewHolder();
            convertView = viewHolder.inflateLayout();
            viewHolder.initView(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (BaseViewHolder<T>) convertView.getTag();
        }
        // 设置数据
        T rowData = (T) getItem(position);

        viewHolder.fillData(rowData, position);

        return convertView;
    }

    public BaseViewHolder<T> getViewHolder() {
        return viewHolder;
    }

}
